﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.Models.Users;
using Think.Lenovo.Com.DataAccess;
using Think.Lenovo.Com.Common;
using System.Configuration;
namespace Think.Lenovo.Com.home
{
    public partial class messageboard : System.Web.UI.Page
    {
        public ViewUserModel user;
        protected void Page_Load(object sender, EventArgs e)
        {
            #region//判断登录
            try
            {
                user = (ViewUserModel)Session["User"];
            }
            catch (Exception ex)
            {
                String logFolder = ConfigurationManager.AppSettings["LogRoot"];
                Log.RecordLog(logFolder, ex);
                Response.Redirect("/home/login.aspx");
            }
            if (user != null)
            {
                if (user.Id < 1)
                {
                    Response.Redirect("Login.aspx");
                    return;
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
                return;
            }

            #endregion
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                MessageBoardModel model = new MessageBoardModel();
                model.Title = this.MessagTitle.Value;
                model.Message = this.MessageContent.Value;
                model.AddUserId = user.Id;
                model.AddDate = DateTime.Now;
                MessageBoard mb = new MessageBoard();
                int id = mb.AddMessage(model);
                if (id > 0)
                {
                    Response.Write("<script type=\"text/javascript\">");
                    Response.Write("alert(\"添加成功\")");
                    Response.Write("</script>");
                }
                else
                {
                    Response.Write("<script type=\"text/javascript\">");
                    Response.Write("alert(\"添加失败\")");
                    Response.Write("</script>");
                }
            }
            catch (Exception ex)
            {

            }
        }
    }
}